<?php

// +----------------------------------------------------------------------

// | Fanwe 多语商城建站系统 (Build on ThinkPHP)

// +----------------------------------------------------------------------

// | Copyright (c) 2009 http://www.fanwe.com All rights reserved.

// +----------------------------------------------------------------------

// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )

// +----------------------------------------------------------------------

// | Author: awfigq(67877605@qq.com)

// +----------------------------------------------------------------------



// 团购券

class GoodsBondAction extends CommonAction{

	public function __construct()

	{

		$goods_id = intval(Session::get('goods_id'));

		if($goods_id==0 || isset($_REQUEST['goods_id']))

		{

			$goods_id = intval($_REQUEST['goods_id']);

		}

		

		Session::set('goods_id',$goods_id);

	

		parent::__construct();

		

		if(!Session::is_set('goods_id'))

			$this->redirect('ExchangeGoods/index');

			

		$this->assign('goods_id',Session::get('goods_id'));

	}

	

	public function index()

	{

		$goods_id = Session::get('goods_id');

		

		$name = trim($_REQUEST['user_name']);

		

		$where="gb.id is not null and gb.goods_id = $goods_id";

		

		if(!empty($name))

		{

			$this->assign("name",$name);

			$where.=" and u.user_name like '%$name%'";

			$parameter .= "name=" . urlencode($name)."&";

		}

		

		if($status != "" && $status >= 0)

		{

			$where.=" and gb.user_id > 0";

			$parameter .= "status=" . $status ."&";

			$this->assign("status",$status);

		}

		else

		{

			$this->assign("status",-1);

		}

		

		$sql = 'SELECT gb.*,u.user_name '.

					'FROM '.C("DB_PREFIX").'goods_bond as gb '.

					'left join '.C("DB_PREFIX").'user as u on u.id = gb.user_id '.

					"where $where";

		$model = M();

		

        $voList = $this->_Sql_list($model, $sql, "&".$parameter, 'id', false);

		

		$this->display ();

		return;

	}

	

	public function add()

	{

		$goods_id = Session::get('goods_id');

		

		$sql = 'SELECT g.name,g.city,s.name as site_name '.

					'FROM '.C("DB_PREFIX").'goods as g '.

					'left join '.C("DB_PREFIX").'site as s on s.id = g.site_id '.

					"where g.id = $goods_id";

		

		$goods = M()->query($sql);

		$this->assign ('goods', $goods[0]);

		$this->display ();

	}

	

	public function edit() {

		$model = D (MODULE_NAME);

		$id = $_REQUEST [$model->getPk ()];

		

		$sql = 'SELECT gb.*,g.name,g.city,g.site_name,u.user_name '.

					'FROM '.C("DB_PREFIX").'goods_bond as gb '.

					'left join '.C("DB_PREFIX").'goods as g on g.id = gb.goods_id '.

					'left join '.C("DB_PREFIX").'user as u on u.id = gb.user_id '.

					"where gb.id = $id";

		

		$gb = M()->query($sql);

		$this->assign ('vo', $gb[0]);

		

		$this->display();

	}

}

?>